var app=new Vue({
    el: '#app',
    data:{
        logList: [],
        searchLog:{
            total:0,
            pageSize:10,
            pageIndex:1,
            startEndDate: ""
        },
        dicts:{
            type: [],
            status: [],
            system: []
        }
    },
    methods:{
        init: function(){
            var _this=this;
            setTimeout(function(){
                _this.initDict();
                _this.findAll();
            },100);
        },
        exportExcel: function(){
            window.location.href=jsmile.url+"/sys/log/export?"+$.param(this.searchLog);
        },
        query: function(){
            this.searchLog.pageIndex=1;
            this.findAll();
        },
        /**
         * 初始化数据字典
         */
        initDict: function(){
            var _this=this;
            var s=jsmile.copy([],jsmile.dict.sf);
            s.unshift({dictName:"全部状态",dictValue:null});
            _this.dicts.status=s;

            jsmile.http.sendJson({
                url:jsmile.url+"/sys/dict/findDictByCode",
                data:{"dictCode":"LO01"}
            }).done(function(res){
                res.resData.splice(0,0,{dictName:"全部",dictValue:null});
                _this.dicts.type=res.resData;
            });
            jsmile.http.sendJson({
                url:jsmile.url+"/sys/dict/findDictByCode",
                data:{"dictCode":"XT02"}
            }).done(function(res){
                res.resData.list.splice(0,0,{dictName:"全部系统",dictValue:null});
                _this.dicts.system=res.resData.list;
            });
        },
        handleSizeChange: function(val) {
            this.searchLog.pageSize=val;
            this.findAll();
        },
        handleCurrentChange: function(val) {
            this.searchLog.pageIndex=val;
            this.findAll();
        },
        goHome: function(url){
            top.$('#home').attr("src","homePage/home.html");
        },
        /*
         * 获取所有数据
         */
        findAll: function(){
            if(!this.searchLog.startEndDate){
                this.searchLog.startEndDate="";
            }else{
                this.searchLog.startTime=this.searchLog.startEndDate[0];
                this.searchLog.endTime=this.searchLog.startEndDate[1];
            }
            var _this=this;
            jsmile.http.sendJson({
                url:jsmile.url+"/sys/log/findAll",
                data:_this.searchLog
            }).done(function(res){
               _this.logList=res.resData.list;
               _this.searchLog.total=res.resData.total;
            }).fail(function(res){
                jsmile.msg.error(res.resMsg?res.resMsg:"获取日志列表失败!");
            });;
        }
    }
});
$(function(){
    init();
    function init(){
        app.init();
    }
});